package 单表查询;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Demo01 {
    public static void main(String[] args) throws Exception{
//        1.加载驱动com.mysql.jdbc.Driver
        Class.forName("com.mysql.jdbc.Driver");
//        2.使用驱动管理器（DriverManager）链接数据库
        String url="jdbc:mysql://localhost:3306/db_jdbc_demo20"+
                "?characterEncoding=utf8&useSSL=false&serverTimezone=UTC";

        String user="root";
        String pass="006688";
        Connection conn = DriverManager.getConnection(url, user, pass);
//        3.书写sql语句
        String sql="SELECT *from t_user";
//        4.创建执行sql的对象
        Statement  stmt= conn.createStatement();
        ResultSet rs = stmt.executeQuery(sql);
//        5.从rs中取出结果
        while (rs.next()){
            String username = rs.getString("username");
            String fullname = rs.getString("fullname");
            System.out.println(username+","+fullname);
        }
//        6.关闭链接
        rs.close();
        stmt.close();
        conn.close();
    }
}
